/*
 * Copyright 2011 myTDev.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mytdev.commons.util;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Yann D'Isanto
 */
public final class ClassUtil {

    private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_CLASSES;
    private static final Map<Class<?>, Class<?>> WRAPPER_PRIMITIVE_TYPES;

    static {
        PRIMITIVE_WRAPPER_CLASSES = new HashMap<Class<?>, Class<?>>();
        PRIMITIVE_WRAPPER_CLASSES.put(Boolean.TYPE, Boolean.class);
        PRIMITIVE_WRAPPER_CLASSES.put(Byte.TYPE, Byte.class);
        PRIMITIVE_WRAPPER_CLASSES.put(Character.TYPE, Character.class);
        PRIMITIVE_WRAPPER_CLASSES.put(Double.TYPE, Double.class);
        PRIMITIVE_WRAPPER_CLASSES.put(Float.TYPE, Float.class);
        PRIMITIVE_WRAPPER_CLASSES.put(Integer.TYPE, Integer.class);
        PRIMITIVE_WRAPPER_CLASSES.put(Long.TYPE, Long.class);
        PRIMITIVE_WRAPPER_CLASSES.put(Short.TYPE, Short.class);

        WRAPPER_PRIMITIVE_TYPES = new HashMap<Class<?>, Class<?>>();
        WRAPPER_PRIMITIVE_TYPES.put(Boolean.class, Boolean.TYPE);
        WRAPPER_PRIMITIVE_TYPES.put(Byte.class, Byte.TYPE);
        WRAPPER_PRIMITIVE_TYPES.put(Character.class, Character.TYPE);
        WRAPPER_PRIMITIVE_TYPES.put(Double.class, Double.TYPE);
        WRAPPER_PRIMITIVE_TYPES.put(Float.class, Float.TYPE);
        WRAPPER_PRIMITIVE_TYPES.put(Integer.class, Integer.TYPE);
        WRAPPER_PRIMITIVE_TYPES.put(Long.class, Long.TYPE);
        WRAPPER_PRIMITIVE_TYPES.put(Short.class, Short.TYPE);
    }

    private ClassUtil() {
    }

    public static Class<?> getPrimitiveWrapperClass(Class<?> primitiveType) {
        return PRIMITIVE_WRAPPER_CLASSES.get(primitiveType);
    }

    public static Class<?> getWrapperPrimitiveType(Class<?> primitiveType) {
        return WRAPPER_PRIMITIVE_TYPES.get(primitiveType);
    }
}
